var layerId;
var flag=true;
$(function(){
	$("#search-button").click(function(){
		var keyword=$("input[name='keyword']").val();
		var gradeId = $("select[name='gradeId']").val();
		var url=basePath+"/appUser/query.shtml?pageNo=1"+"&keyword="+keyword+"&gradeId="+gradeId;
		window.location.href=url;
	});
	$("#updateGrade-button").click(function(){
		var gradeId = $("select[name='gradeId']").val();
		var userIds = $(".user-checkbox:checked");
		if(userIds.length==0){
			layer.msg("请选择用户");
			return false;
		}
		if(gradeId.length==0){
			layer.msg("请选择等级");
			return false;
		}
		var userIdArray = new Array();
		for(i=0;i<userIds.length;i++){
			var id = $(userIds[i]).val();
			userIdArray.push(id);
		}
		var idStr=userIdArray.toString();
		if(flag){
			 flag =false;
			 $.ajax({
		  		 url:basePath+"/appUser/saveGrade.shtml", 
		  		 data:{"userIds":idStr,"gradeId":gradeId},
		  		 type:"post",
		  		 dataType:"JSON",
		  		 success:ajaxSuccessRefreshFun
		  	 });
		}
	});
	
})
function fanye(pageNo){
	var url=basePath+"/appUser/query.shtml?pageNo="+pageNo+"&keyword="+init.keyword+"&gradeId="+init.gradeId;
	window.location.href=url;
}

function checkAll(e){
	var flag=$(e).prop("checked");
	if(flag){
		$(".user-checkbox").prop("checked",true);
	}else{
		$(".user-checkbox").prop("checked",false);
	}
}
function editMoneyFun(userId,type){
	layerId=layer.open({
		title: "修改余额",
		area: ['1200px','700px'],
		fix:true,
		type: 2,
		content: basePath+'/appUser/editMoney.shtml?userId='+userId+'&type='+type
	});
}
function moneyListFun(userId){
	layerId=layer.open({
		title: "余额记录",
		area: ['1200px','700px'],
		fix:true,
		type: 2,
		content: basePath+'/appUser/queryMoneyLog.shtml?userId='+userId
	});
}